// pages/admin_z/admin_z.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uList: [],
    type: '子管理员',
    name: '子管理员'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  userList: function () {
    var that = this
    wx.request({
      url: app.globalData.api + 'user/list',
      data: {
        page: 1,
        rows: 999,
        roleName: this.data.type
      },
      method: 'POST',
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function (res) {
        console.log(res)
        if (res.data.code == 200) {
          that.setData({
            uList: res.data.data.userList
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.userList()
  },
  addAccount: function () {
    wx.navigateTo({
      url: '/pages/account/account?type=' + this.data.type
    })
  },
  edlitUser: function (e) {
    wx.navigateTo({
      url: '/pages/account/account?type=' + this.data.type + '&id=' + e.currentTarget.dataset.id,
    })
  },
  deleUser: function (e) {
    var that = this
    wx.showModal({
      title: '提示',
      content: '确认删除?',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.api + 'user/' + e.currentTarget.dataset.id,
            data: {},
            header: {
              Authorization: wx.getStorageSync('token')
            },
            method: 'DELETE',
            success: (res) => {
              if (res.data.code == 200) {
                wx.showToast({
                  title: '删除成功',
                })
                that.userList()
              }
            }
          })
        }
      }
    })
  },

})